package com.persondemo.videoappliction.ui.dianping.presenter;

import com.persondemo.videoappliction.bean.DianPingBean;
import com.persondemo.videoappliction.bean.DianPingChoiceBean;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.dianping.contract.DianpingContract;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.ui.base.BasePresenter;

import javax.inject.Inject;

public class DianPingPresenter extends BasePresenter<DianpingContract.View> implements DianpingContract.Persenter {
    BaseApi baseApi;

    @Inject
    public DianPingPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getchoice(String city) {
        baseApi.getchoice(city)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<DianPingChoiceBean>() {
                    @Override
                    public void onSuccess(DianPingChoiceBean dianPingChoiceBean) {
                        mView.loadchoice(dianPingChoiceBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void getpingce(String xlocation, String ylocation, String type, String key, String paid, String page, String xid, String city) {
        baseApi.getpingce(xlocation, ylocation, type, key, paid, page, xid, city)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<DianPingBean>() {
                    @Override
                    public void onSuccess(DianPingBean dianPingBean) {
                        if (page.equals("1")){
                            mView.loadpingce(dianPingBean);
                        }else {
                            mView.loadpingcemore(dianPingBean);
                        }

                    }
                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
